package main

import (
	"github.com/adjust/redismq"
	"fmt"
	"github.com/nofuck/instagram"
	"log"
	"time"
)

func DownloadImage() {
	testQueue, err := redismq.SelectQueue("123.207.14.208", "6379", "firely0506", 0, "ins_urls")
	if err != nil {
		fmt.Println(err)
		return
	}
	consumer, err := testQueue.AddConsumer("c_" + string(time.Now().Unix()))
	if err != nil {
		log.Println(err)
	}
	consumer.ResetWorking()
	for {
		p, err := consumer.Get()
		if err != nil {
			log.Println(err)
			continue
		}
		log.Println("[info] Start download image, " + p.Payload)
		instagram.SaveImage(p.Payload, "/data/instagram/img/")
		err = p.Ack()
		if err != nil {
			log.Println(err)
			continue
		}
	}

	consumer.Quit()
}
